from weibo1 import APIClient, OAuthToken
import weibo_common

t = weibo_common.read_token()
print("t=" + t[0] + t[1] + t[2])
oauth_token = t[0]
oauth_token_secret = t[1]
oauth_verifier = t[2]
#print(oauth_token+ oauth_token_secret+oauth_verifier)

app_key = weibo_common.APP_KEY
app_secret = weibo_common.APP_SECRET

#oauth_verifier = your.web.framework.request.get('oauth_verifier')

#oauth_token_secret = load_request_token_secret_from_db(oauth_token)

request_token = OAuthToken(oauth_token, oauth_token_secret, oauth_verifier)

client = APIClient(app_key=app_key, app_secret=app_secret, token=request_token)
access_token = client.get_access_token()

client = APIClient(app_key, app_secret, access_token)
account = client.account__verify_credentials()
uid = account.id
print(uid)

#save_access_token_to_db(uid, access_token.oauth_token, access_token.oauth_token_secret)

user_id = uid
#access_token = load_access_token_from_db(user_id);
client = APIClient(app_key=app_key, app_secret=app_secret, token=access_token)
print client.get.statuses__user_timeline()
print client.post.statuses__update(status=u'test hello world')

